package com.qingke.easyjava;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;

public class LifecycleBean
		implements BeanNameAware, BeanPostProcessor, BeanFactoryAware, InitializingBean, DisposableBean {
	
	public void init(){
		System.out.println("calling LifecycleBean.init()");
	}

	public void destroy() throws Exception {
		// TODO Auto-generated method stub
		System.out.println("calling LifecycleBean.destroy()");
	}
	
	public void close(){
		System.out.println("calling LifecycleBean.close()");
	}

	public void afterPropertiesSet() throws Exception {
		// TODO Auto-generated method stub
		System.out.println("calling LifecycleBean.afterPropertiesSet()");
	}

	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		// TODO Auto-generated method stub
		((DefaultListableBeanFactory)beanFactory).addBeanPostProcessor(this);
		System.out.println("calling LifecycleBean.setBeanFactory()");
	}

	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		// TODO Auto-generated method stub
		System.out.println("calling LifecycleBean.postProcessBeforeInitialization(),beanName= "+beanName);
		return bean;
	}

	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		// TODO Auto-generated method stub
		System.out.println("calling LifecycleBean.postProcessAfterInitialization(),beanName="+beanName);
		return bean;
	}

	public void setBeanName(String name) {
		// TODO Auto-generated method stub
		System.out.println("calling LifecycleBean.setBeanName(),name= "+name);

	}

}
